package handlers

import (
	"github.com/gin-gonic/gin"
	"order-master1/models"
	"strconv"
)

func AddGoods(c *gin.Context) {
	goods_name := c.PostForm("goods_name")
	price, _ := strconv.Atoi(c.PostForm("price"))
	if goods_name == "" || price == 0 {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "数据不能为空",
		})
		return
	}

	goods := models.Goods{
		GoodsName: goods_name,
		Price:     price,
	}

	err := models.DB.Create(&goods).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
	return
}
